Function.prototype.getBody=function () {
	var func=this.toString();
	return func.substring(func.indexOf("{")+1, func.lastIndexOf("}"));
}

Function.prototype.getName= function () {
  var name = this.toString().match(/function (\w*)/)[1];
  if ((name == null) || (name.length == 0))
    name = 'anonymous';
  return name;
}

Array.prototype.hasValue=function (value) {
	return this.firstIndexOf(value)>-1;
}

Array.prototype.firstIndexOf=function (value) {
	for (var i=0; i<this.length; i++){
		if (this[i]==value) return i;
	}
	return -1;
}

Array.prototype.lastIndexOf=function (value) {
	for (var i=this.length-1; i>=0; i--){
		if (this[i]==value) return i;
	}
	return -1;
}

Array.prototype.removeAt = function (index) {
	var arr=index>0?this.slice(0,index):new Array();
	for (var i=index+1; i<this.length; i++) {
	    arr.push(this[i]);
	}
	this.copy(arr);
}

Array.prototype.removeAll =function (value) {
	var arr=new Array();
	for (var i=0; i<this.length; i++){
		if (this[i]!=value) arr.push(this[i]);
	}
	this.copy(arr);
}

Array.prototype.copy=function (arr) {
	while (this.length>0){
		this.pop();
	}
	for (var i=0; i<arr.length; i++){
		this[i]=arr[i];
	}
}

Array.prototype.toString = function () {
    var str = String.format("Array({0})=[", this.length);
    for (var i=0; i<this.length; i++) {
        str += this[i];
        str += (i<this.length-1)?", ":"";
    }
    str += "]";
    return str;
}

String.prototype.trim=function () {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.endsWith=function (str) {
	return this.substring(this.length-str.length, this.length)==str;
}

String.format=function () {
	if (arguments.length==0){
		return "";
	}
	var format=arguments[0];
	for (var i=1; i<arguments.length; i++){
		format=format.replace(new RegExp("\\{"+(i-1)+"\\}", "g"), Utils.isDefined(arguments[i])?arguments[i].toString():"");
	}
	return format;
}

String.safeConcat=function (str1, str2, delimiter){
	if (!str1||str1=="") return str2;
	if (!str2||str2=="") return str1;
	return str1+delimiter+str2;
}


String.prototype.isNullOrEmpty = function () {
    return (this==null||this=="");
}